package share.seckill.module.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import share.seckill.module.domain.User;
import share.seckill.core.result.Result;
import share.seckill.module.service.UserService;

@Controller
public class DemoController {
	
	@GetMapping("hello")
	public Result<String> hello(){
		return Result.success("helloword");
	}
	
	@RequestMapping("/thymeleaf")
	public String thymeleaf(Model model) {
		model.addAttribute("name", "Joshua");
		return "hello";
	}
	@Autowired
	UserService userService;

	@RequestMapping("/db/get")
	@ResponseBody
	public  Result<User> getSql(){

		User user=  userService.getById(1);

		return Result.success(user);
	}

	@RequestMapping("/db/tx")
	@ResponseBody
	public  Result<Boolean> testTx(){

		return Result.success(userService.tx());
	}
}
